use time::Duration;
use time::PrimitiveDateTime as DateTime;

fn after(start: DateTime) -> DateTime {
    start.saturating_add(Duration::seconds(1_000_000_000))
}

#[cfg(test)]
mod tests {
    use super::*;
    use time::Date;
    use time::Time;

    fn dt(year: i32, month: u8, day: u8, hour: u8, minute: u8, second: u8) -> DateTime {
        DateTime::new(
            Date::from_calendar_date(year, month.try_into().unwrap(), day).unwrap(),
            Time::from_hms(hour, minute, second).unwrap(),
        )
    }

    #[test]
    fn test_date() {
        let start_date = dt(2011, 4, 25, 0, 0, 0);
        let end_date = dt(2043, 1, 1, 1, 46, 40);
        assert_eq!(after(start_date), end_date);
    }

    #[test]
    fn test_another_date() {
        let start_date = dt(1977, 6, 13, 0, 0, 0);
        let end_date = dt(2009, 2, 19, 1, 46, 40);
        assert_eq!(after(start_date), end_date);
    }

    #[test]
    fn test_third_date() {
        let start_date = dt(1959, 7, 19, 0, 0, 0);
        let end_date = dt(1991, 3, 27, 1, 46, 40);
        assert_eq!(after(start_date), end_date);
    }

    #[test]
    fn test_datetime() {
        let start_date = dt(2015, 1, 24, 22, 0, 0);
        let end_date = dt(2046, 10, 2, 23, 46, 40);
        assert_eq!(after(start_date), end_date);
    }

    #[test]
    fn test_another_datetime() {
        let start_date = dt(2015, 1, 24, 23, 59, 59);
        let end_date = dt(2046, 10, 3, 1, 46, 39);
        assert_eq!(after(start_date), end_date);
    }
}
